namespace TSL.DAL
{
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using System;
    using System.Data;
    using System.Data.Common;
    using System.Text;

    public class OpenCodes
    {
        public void CloseCaipiao(int ssc_id, string lottery_num)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("CloseCaipiao");
            db.AddInParameter(dbCommand, "ssc_id", DbType.Int32, ssc_id);
            db.AddInParameter(dbCommand, "lottery_num", DbType.AnsiString, lottery_num);
            db.ExecuteNonQuery(dbCommand);
        }

        public void FanDian(string username, string xusername, string lottery_id, string expect, string protype, double winmoney)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("Opencodes");
            db.AddInParameter(dbCommand, "username", DbType.AnsiString, username);
            db.AddInParameter(dbCommand, "xusername", DbType.AnsiString, xusername);
            db.AddInParameter(dbCommand, "wininfo", DbType.AnsiString, null);
            db.AddInParameter(dbCommand, "protype", DbType.AnsiString, protype);
            db.AddInParameter(dbCommand, "type", DbType.AnsiString, expect);
            db.AddInParameter(dbCommand, "winmoney", DbType.Decimal, winmoney);
            db.AddInParameter(dbCommand, "lotteryid", DbType.AnsiString, lottery_id);
            db.AddInParameter(dbCommand, "bz", DbType.Int32, 4);
            db.ExecuteNonQuery(dbCommand);
        }

        public DataSet GetListOpenCodes(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from V_GetListOpenCodes");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by id desc");
            return DatabaseFactory.CreateDatabase().ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        public DataSet GetSscCodes(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from V_ssc_info");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by id desc");
            return DatabaseFactory.CreateDatabase().ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        public void MyFanDian(string username, string lottery_id, string expect, string protype, double winmoney)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("Opencodes");
            db.AddInParameter(dbCommand, "username", DbType.AnsiString, username);
            db.AddInParameter(dbCommand, "xusername", DbType.AnsiString, null);
            db.AddInParameter(dbCommand, "wininfo", DbType.AnsiString, null);
            db.AddInParameter(dbCommand, "protype", DbType.AnsiString, protype);
            db.AddInParameter(dbCommand, "type", DbType.AnsiString, expect);
            db.AddInParameter(dbCommand, "winmoney", DbType.Decimal, winmoney);
            db.AddInParameter(dbCommand, "lotteryid", DbType.AnsiString, lottery_id);
            db.AddInParameter(dbCommand, "bz", DbType.Int32, 3);
            db.ExecuteNonQuery(dbCommand);
        }

        public void Opencodes(string username, int wininfo, string lottery_id, string expect, string protype, double winmoney)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("Opencodes");
            db.AddInParameter(dbCommand, "username", DbType.AnsiString, username);
            db.AddInParameter(dbCommand, "xusername", DbType.AnsiString, null);
            db.AddInParameter(dbCommand, "wininfo", DbType.AnsiString, wininfo);
            db.AddInParameter(dbCommand, "protype", DbType.AnsiString, protype);
            db.AddInParameter(dbCommand, "type", DbType.AnsiString, expect);
            db.AddInParameter(dbCommand, "winmoney", DbType.Double, winmoney);
            db.AddInParameter(dbCommand, "lotteryid", DbType.AnsiString, lottery_id);
            db.AddInParameter(dbCommand, "bz", DbType.Int32, 5);
            db.ExecuteNonQuery(dbCommand);
        }

        public void UnWin(string username, string lottery_id, string expect)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("UnWinCode");
            db.AddInParameter(dbCommand, "username", DbType.AnsiString, username);
            db.AddInParameter(dbCommand, "expect", DbType.AnsiString, expect);
            db.AddInParameter(dbCommand, "lotteryid", DbType.AnsiString, lottery_id);
            db.ExecuteNonQuery(dbCommand);
        }
    }
}

